import { ResultCallback, ResultState, SDKStyle } from "../../SDKDefine";
import { SDKChannelType } from "../../SDKConfig";

export abstract class SDKSystem {
    protected visibleSize: { width: number, height: number } = { width: 1, height: 1 };

    protected clientScaleX: number = 1;

    protected clientScaleY: number = 1;

    protected data: SDKChannelType;

    protected sdk: any;
    /**
     * 显示宽高与小游戏屏幕宽高的比例
     */
    protected screenRatio: { x: number, y: number } = { x: 1, y: 1 }

    getScreenSize(): { width: number, height: number } {
        return { width: 0, height: 0 }
    }

    setScreenRatio() {
        let visibleSize = this.getVisibleSize();
        console.log(' visibleSize ', visibleSize)
        let screenSize = this.getScreenSize();

        this.screenRatio.x = screenSize.width / visibleSize.width
        this.screenRatio.y = screenSize.height / visibleSize.height
    }

    getScreenRatio() {
        return this.screenRatio;
    }



    changeStyle(style: SDKStyle) {
        let screenRatio = this.getScreenRatio();
        console.log('changeStyle screenRatio ', screenRatio)
        // let style = param.style;
        if (style.left != undefined) {
            style.left = style.left * screenRatio.x;
        }
        if (style.top != undefined) {
            style.top = style.top * screenRatio.y;
        }
        if (style.width != undefined) {
            style.width = style.width * screenRatio.x;
        }
        if (style.height != undefined) {
            style.height = style.height * screenRatio.y;
        }
    }

    setSDK(sdk: any) {
        this.sdk = sdk;
    }

    getParamValue(adName: string) {
        return this.data[adName]
    }

    getSDK(): any {
        return this.sdk;
    }

    setData(d: SDKChannelType) {
        this.data = d;
    }

    init() {

    }

    compareVersion(version: string): number {
        return 0;
    }

    setClientScaleX(x: number) {
        this.clientScaleX = x;
    }

    setClientScaleY(n: number) {
        this.clientScaleY = n;
    }

    getClientScaleY() {
        return this.clientScaleY
    }

    getClientScaleX() {
        return this.clientScaleX
    }

    setVisibleSize(s: { width: number, height: number }) {
        this.visibleSize = s;
        // console.log(' setVisibleSize  this.visibleSize ', this.visibleSize)
        this.setScreenRatio()
    }

    getVisibleSize() {
        return this.visibleSize;
    }

    exitApplication() {

    }
    hasVibration() {
        return true;
    }

    //短震动
    vibrateShort() {

    }
    //展示网络图片
    previewImage(imgUrl: string) {

    }
    //跳转能力
    navigateToMiniProgram(appID: string) {

    }


    postMessage(msg: any) {

    }







    showToast(title: string) {

    }

    canInstallShortcut(func: ResultCallback) {
        func(ResultState.NO)
    }

    /**
     * 安装图标到桌面
     * @param result 
     */
    installShortcut(result: ResultCallback) {
        result(ResultState.NO)
    }


    //创建更多游戏按钮
    createMoreGameButton(xr: number, yr: number, w: number, h: number) {

    }

    hideMoreGameButton() {

    }
    //显示更多游戏面板
    showMoreGameView() {

    }


    loadConfig() {

    }

    createCanvas() {

    }

    cantUseImageDataURL() {
        return true;
    }

    request(url: string, func: Function) {
        // this.sdk.request({
        //     url: url, //仅为示例，并非真实的接口地址
        //     timeout: 15000,
        //     header: {
        //         'content-type': 'application/json', // 默认值
        //         'If-Modified-Since': '0'
        //     },
        //     success(res) {
        //         // console.log('request success', res.data)
        //         func(null, res.data)
        //     },
        //     fail(err) {
        //         // console.log('request err', err)
        //         func(' error ', err)
        //     }
        // })
    }


    /**
     * 保存文件 
     * @param filename 
     * @param content 
     */
    saveFile(filename: string, content: string) { }


    createGameClubButton(param?: any) { }


    //游戏更新提醒
    requestSubscribeSystemMessage() {

    }
    destroyInfoButton(): void { }
    setInfoButtonVisible(flag: boolean) { }
    getSetting(obj: { scope: string, callback: ResultCallback }): void { }
    authorize(obj: { scope: string, callback: ResultCallback }): void { }
    getUserInfo(param: { callback: (r: ResultState, res: any) => void }): void { }
    setUserCloudStorage(param: { key: string, value: any, callback: ResultCallback }): void { }
    createInfoButton(param: { type: string, text?: string, image?: string, style: SDKStyle, callback: (r: ResultState, data?: any) => void }): void { }
}